﻿namespace Spectro.Cards.Actions.Physical
{
    /// <summary>
    /// Drub action
    /// </summary>
    public class Drub : IPhysicalAction
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Drub"/> class.
        /// </summary>
        public Drub()
        {
            Damage = 2;
        }

        /// <summary>
        /// Gets or sets the damage.
        /// </summary>
        /// <value>
        /// The damage.
        /// </value>
        public int Damage { get; set; }

        /// <summary>
        /// Gets or sets the warior.
        /// </summary>
        /// <value>
        /// The warior.
        /// </value>
        public Warior Warior { get; set; }

        /// <summary>
        /// Executes the specified defender.
        /// </summary>
        /// <param name="defender">The defender.</param>
        /// <param name="attacker">The attacker.</param>
        public void Execute(Gamer defender, Gamer attacker)
        {
            var position = Warior.Position;

            switch (position)
            {
                case 0:
                {
                    AppleAttack(defender, attacker, defender.Wariors[1]);
                    break;
                }
                case 4:
                {
                    AppleAttack(defender, attacker, defender.Wariors[3]);
                    break;  
                }
                default:
                {
                    AppleAttack(defender, attacker, defender.Wariors[position + 1]);
                    AppleAttack(defender, attacker, defender.Wariors[position - 1]);
                    break;     
                }
            }
        }

        private void AppleAttack(Gamer defender, Gamer attacker, IEssence point)
        {
            if (point != null)
            {
                if (point.IsCanExecuteEction(this, attacker, defender))
                {
                    point.Health = point.Health - Damage;
                    if (point.Health <= 0) point = point.Die(attacker, defender);
                }
            }
        }
    }
}
